package com.filyar.htyd.controller;

import cn.hutool.core.date.DateUtil;
import com.filyar.htyd.common.Result;
import com.filyar.htyd.entity.Day;
import com.filyar.htyd.service.IDayService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author filyar
 * @since 2024-08-29
 * @e-mail root@filyar.com
 */
@RestController
@RequestMapping("/day")
public class DayController {

    @Resource
    private IDayService dayService;

    private final String now = DateUtil.now();

    @PostMapping
    public Result save(@RequestBody Day day) {

        dayService.updateDay(day);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        dayService.removeById(id);
        return Result.success();
    }

    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        dayService.removeByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(dayService.getById(id));
    }

    @GetMapping("/page")
    public Result findPage(@RequestParam(required = false) String date) {
        return Result.success(dayService.customList(date));

    }



}

